package com.cn.onetrip.untility;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.util.Log;

public class SBCToDBC {
	/**
	 * SBC to DBC
	 * 
	 * @param input
	 * @return
	 */
	public static String ToDBC(String input) {
		char[] c = input.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 12288) {// SBC blank is 12288��DBC blank is 32
				c[i] = (char) 32;
				continue;
			}
			if (c[i] > 65280 && c[i] < 65375)// others DBC(33-126) - SBC(65281-65374) = 65248
				c[i] = (char) (c[i] - 65248);
		}

		String s = new String(c);
		return s;
	}

	/**
	 * 
	 * @param str
	 * @return
	 */
	public static String stringFilter(String str) {
		str = str.replaceAll("��", "[").replaceAll("��", "]")
				.replaceAll("��", "!").replaceAll("��", ":");// replace chinese
															// tab
		String regEx = "[����]"; // clear special character
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("").trim();
	}

	private void createDiscripbtion(String discripbtion) {
		String s = ToDBC(discripbtion);
		discripbtion = stringFilter(s);
	}

}
